//
//  RecommendMerchantCell.m
//  ImGuider
//
//  Created by 王鹏宇 on 2018/6/4.
//  Copyright © 2018年 imguider. All rights reserved.
//

#import "RecommendMerchantCell.h"
#import "RecommendMerchantDetailVC.h"

@interface RecommendMerchantCell ()

@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@property (weak, nonatomic) IBOutlet UILabel *desLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tapViewHeight;

@property (weak, nonatomic) IBOutlet UIView *tapView;
@end

@implementation RecommendMerchantCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UITapGestureRecognizer * tapCell = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(goRecommendMerchantDetail)];
    [self.tapView addGestureRecognizer:tapCell];
    
//    self.tagView.tagViewWidth = self.tagViewWidth;
    
    self.iconImageView.layer.cornerRadius = 5;
    self.iconImageView.clipsToBounds = YES;
    
    self.tapView.layer.cornerRadius = 5;
    self.tapView.clipsToBounds = YES;
    self.contentView.backgroundColor = [UIColor clearColor];
    self.backgroundColor = [UIColor clearColor];
    self.desLabel.textColor = kContentColor;
    self.tapViewHeight.constant = kScreenWidth/375 * 130 -10;
    if (ISiPhone5 || ISiPhone4) {
        self.desLabel.font = Font(12);
        self.nameLabel.font = Font(14);
        self.desLabel.font = Font(10);
    }
}

- (void)goRecommendMerchantDetail {
    
    RecommendMerchantDetailVC * vc = [[RecommendMerchantDetailVC alloc] init];
    vc.model = self.model;
    vc.hidesBottomBarWhenPushed = YES;
    [self.superVC.navigationController pushViewController:vc animated:YES];
}

- (void)setModel:(MerchantModel *)model {
    
    _model = model;
    
    [self.iconImageView setImageURL:[NSURL URLWithString:model.pictureArray.firstObject] placeholderImage:kPlaceholderSqu];
    
    NSMutableAttributedString *nameAtt = [NSMutableAttributedString new];
    nameAtt.font = Font(17);
    if (model.promotion.count > 0) {
        
        MerchantEventModel *event = model.promotion.firstObject;
        
        NSMutableAttributedString *att = [NSMutableAttributedString new];
        
        if (event.type.length > 0) {
            
            [att appendString:[NSString stringWithFormat:@"【%@】",event.type]];
        } else {
            
            [att appendString:@"【专属优惠】"];
        }
        
        att.color = kThemeRedColor;
        
        [nameAtt appendAttributedString:att];
        
         NSMutableAttributedString *att2 = [[NSMutableAttributedString alloc] initWithString:event.name];
        att2.color = kTitleColor;
        [nameAtt appendAttributedString:att2];
    } else {
        
        [nameAtt appendString:@"专属优惠"];
    }
    
    self.nameLabel.attributedText = nameAtt;
    
    
    NSMutableAttributedString *desAtt = [NSMutableAttributedString new];
    
    NSMutableAttributedString *att1 = [[NSMutableAttributedString alloc] initWithString:model.smartName];
    att1.font = Font(14);
    
    [desAtt appendAttributedString:att1];
    [desAtt appendString:@"\n"];
    desAtt.lineSpacing = 5;
    
    NSMutableAttributedString *att2 = [[NSMutableAttributedString alloc] initWithString:model.address];
    att2.font = Font(12);
    att2.lineSpacing = 1;
    
    [desAtt appendAttributedString:att2];
    
    
    self.desLabel.attributedText = desAtt;

}
@end
